<?php
class StoreAction extends Action{
	public function index(){
		if(!empty($_GET['id'])){
			$seriesStr = new series();
			$storeModel = D("store");
			$seriesModel = D("series");
			$merchandiseModel = D("merchandise");
			$suser = $storeModel->join("suser on suser.suser_id = store.store_mid")
			->where("suser.suser_id='".trim($_GET['id'])."'")->find();
			
			$series = $seriesModel
			->where("series.series_sid='".$suser['store_id']."' and series_mid=''")->find();
			$commoditycount = 0;
			foreach ($seriesStr->seriesStr as $key => $value){
				${'series_'.$value} =  $merchandiseModel
					->where("mcd_sid='".$suser['store_id']."' and mcd_type='".$value."' and mcd_mid=''")->findAll();
				${'linecount_'.$value} = floor(count(${'series_'.$value})/5);
				${'surpluscount_'.$value} = count(${'series_'.$value})%5;
				$commoditycount += count(${'series_'.$value});
			}
			
			$seriescountArray = $series;
			$seriescount = count(array_filter($seriescountArray));
			//dump($vo);
			//dump($series);
			
			$this->assign("suser", $suser);
			$this->assign("series",$series);
			$this->assign('commoditycount',$commoditycount);
			foreach ($seriesStr->seriesStr as $key => $value){
				$this->assign("series_".$value,${'series_'.$value});
				$this->assign("linecount_".$value,${'linecount_'.$value});
				$this->assign("surpluscount_".$value,${'surpluscount_'.$value});
				$this->assign("commoditycount_".$value,count(${'series_'.$value}));
			}
			$this->assign("seriescount",$seriescount-1);
			$this->display();
		}else{
			$this->redirect('Index/index');
		}
	}
	
//显示商品信息
	public function showCommodity(){
		if(!empty($_GET['mcd_mid']) && !empty($_GET['id'])){
			$seriesStr = new series();
			$storeModel = D("store");
			$seriesModel = D("series");
			$merchandiseModel = D("merchandise");
			$mcd = $merchandiseModel->where("mcd_id='".trim($_GET['mcd_mid'])."'")->find();
			$suser = $storeModel->join("suser on suser.suser_id = store.store_mid")
			->where("suser.suser_id='".trim($_GET['id'])."'")->find();
			//dump($vo);
			//dump($_SESSION);
			$newSeriesId = $_GET['mcd_mid']."_".$_GET['level'];
			$series = $seriesModel
			->where("series_sid='".$newSeriesId."'")->find();

			$commoditycount = 0;
			$seriescount = 0;
			foreach ($seriesStr->seriesStr as $key => $value){
				${'series_'.$value} =  $merchandiseModel
					->where("mcd_sid='".$newSeriesId."' and mcd_type='".$value."' and mcd_mid='".trim($_GET['mcd_mid'])."'")->findAll();
				${'linecount_'.$value} = floor(count(${'series_'.$value})/5);
				${'surpluscount_'.$value} = count(${'series_'.$value})%5;
				$commoditycount += count(${'series_'.$value});
				if(count(${'series_'.$value})!=0){
					$seriescount+=1;
				}
			}

			//dump($series);
			$seriescountArray = $series;
			//dump($vo);
			//dump(${'series_'."C"});
			$this->assign('level',intval($_GET['level'])+1);
			$this->assign('mcd',$mcd);
			$this->assign("suser", $suser);
			$this->assign("series",$series);
			$this->assign('commoditycount',$commoditycount);
			foreach ($seriesStr->seriesStr as $key => $value){
				$this->assign("series_".$value,${'series_'.$value});
				$this->assign("linecount_".$value,${'linecount_'.$value});
				$this->assign("surpluscount_".$value,${'surpluscount_'.$value});
				$this->assign("commoditycount_".$value,count(${'series_'.$value}));
			}
			$this->assign("seriescount",$seriescount);
			$this->display();
		}else{
			$this->redirect('index');
		}
	}
}
//商品系列类
class series{	
	public $seriesStr=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
}